﻿/*
 *
 * task.h
 *
 *  Created on: 2016��11��4��
 *      Author: chenshisheng
 */

#ifndef INC_TASK_H_
#define INC_TASK_H_


#include "main.h"

typedef uint8_t TASK_Bits_t;

extern TASK_Bits_t __taskBits;

typedef enum
{
    Task_Id_WatchDog = 0,
    Task_Id_FrameIn,
    Task_Id_Sensor,
    Task_Id_ClearCalibration,

    Task_Id_Max
}TASK_Id_t;

#define TASK_SET(id) (__taskBits |= (uint8_t)(1u << (id)))
#define TASK_CLR(id) (__taskBits &= (uint8_t) ~(1u << (id)))
#define TASK_HAVE(id) (__taskBits & (uint8_t)(1u << (id)))
#define TASK_BIT(id) (1u << (id))
#define TASK_BIT_HAVE(bit) (__taskBits & (uint8_t)(bit))
#define TASK_BIT_CLR(bit) (__taskBits &= ~ (uint8_t)(bit))
#define TASK_HAVE_ANY() (__taskBits != 0)

#define TASK_SCHEDULE(id, foo) if(TASK_HAVE(id)) {\
    foo; \
    TASK_CLR(id);}

void Task_Init(void);
void TASK_Idle(void);
void TASK_Act(void);

#endif /* INC_TASK_H_ */
